package com.vmj.instructions.base;

import com.vmj.heap.Method;
import com.vmj.rtda.Frame;
import com.vmj.rtda.Slot;
import com.vmj.rtda.Thread;

/**
 * Created by yangshoujun on 2017/9/2 下午2:04.
 */
public class MethodInvokeLogic {

    public static void invokeMethod(Frame frame, Method method) {
        Thread thread = frame.getThread();
        Frame newFrame = new Frame(thread, method);
        thread.pushFrame(newFrame);
        int paramCount = method.getArgSlotCount();
        if(paramCount > 0) {
            for(int i = paramCount - 1;i >= 0;i--) {
                Slot slot = frame.getOperandStack().popSlot();
                newFrame.getLocalVars().setSlot(i, slot);
            }
        }
    }
}
